package com.erp.myAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.erp.notifiactionDb.NotificationBean;
import com.erp.R;
import com.erp.util.Myutil;

import java.util.List;

/**
 * Created by Administrator on 2016/12/21/021.
 * 作者：刘洋
 */
public class NotificationAdapter extends BaseAdapter {
    private Context mcontext;
    private List<NotificationBean> mlist;
    private LayoutInflater minflater;

    public NotificationAdapter(Context context, List<NotificationBean> list) {
        super();
        this.mcontext = context;
        this.mlist = list;
        this.minflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mlist.size();
    }

    @Override
    public Object getItem(int position) {
        return mlist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh = null;
        if (convertView == null) {
            vh=new ViewHolder();
            convertView = minflater.inflate(R.layout.lv_notification_item, null);
            vh.tvNotificationTime= (TextView) convertView.findViewById(R.id.tv_notification_time);
            vh.tvNotificationTitle= (TextView) convertView.findViewById(R.id.tv_notification_title);
            vh.tvNotificationXiangqing= (TextView) convertView.findViewById(R.id.tv_notification_xiangqing);
            vh.tvZhuangtai= (TextView) convertView.findViewById(R.id.tv_zhaungtai);
            convertView.setTag(vh);
        }else{
            vh= (ViewHolder) convertView.getTag();
        }
        NotificationBean notificationBean=new NotificationBean();
        notificationBean=mlist.get(position);
        if(notificationBean.istrue()==false){
            vh.tvZhuangtai.setVisibility(View.VISIBLE);
            vh.tvZhuangtai.setText("未查看");
        }else{
            vh.tvZhuangtai.setVisibility(View.GONE);
        }
        vh.tvNotificationTitle.setText(notificationBean.getTitle());
        vh.tvNotificationXiangqing.setText(notificationBean.getXiangqing());
        if(!notificationBean.getTime().equals("0")) {
            vh.tvNotificationTime.setText(Myutil.getdata(notificationBean.getTime()));
        }
        return convertView;
    }
    class ViewHolder {
         private TextView tvNotificationTitle,tvNotificationXiangqing,tvNotificationTime,tvZhuangtai;
    }
    public void notifiAll(List<NotificationBean> list){
        this.mlist=list;
        notifyDataSetChanged();
    }
}
